FROM debian:stretch-slim
LABEL vendor=433\
      com.433.fastdfs.version="5.11"\
	  com.433.fdht.version="2.0.1"\
	  com.433.db.version="6.2.32"\
	  com.433.version="1.0.0" \
	  com.433.release-date="2017-08-30"

ADD . /fastdfs
RUN set -ex; \
	\
	fetchDeps='ca-certificates wget'; \
	apt-get update; \
	apt-get install -y --no-install-recommends $fetchDeps; \
		\
	buildDeps=' \
		wget \
		\
		gcc \
		libc6-dev \
		make \
		libpcre3 \
		libpcre3-dev \
		openssl \
		libssl-dev \
		libperl-dev \
		zlib1g-dev \
	'; \
	apt-get install -y $buildDeps --no-install-recommends; \
	tools=' \
	procps \
	net-tools \
	vim \
	';\
	apt-get install -y $tools --no-install-recommends; \
	rm -rf /var/lib/apt/lists/*

WORKDIR /fastdfs/libfastcommon-1.0.35
	
RUN set -xe;\
    chmod +x /fastdfs/libfastcommon-1.0.35/make.sh; \
    /fastdfs/libfastcommon-1.0.35/make.sh; \
    /fastdfs/libfastcommon-1.0.35/make.sh install
	
WORKDIR /fastdfs/db-6.2.32/build_unix
RUN set -xe;\
	chmod +x /fastdfs/db-6.2.32/dist/configure; \ 
	/fastdfs/db-6.2.32/dist/configure --prefix=/usr; \
       make; \
       make install
	
WORKDIR /fastdfs/fastdht
RUN set -xe;\
     chmod +x /fastdfs/fastdht/make.sh; \
	/fastdfs/fastdht/make.sh; \
    /fastdfs/fastdht/make.sh install
	
COPY ./start.bash /usr/local/bin/

WORKDIR  /fastdfs/fastdfs-5.11
RUN set -xe; \
	chmod +x /fastdfs/fastdfs-5.11/make.sh; \
    /fastdfs/fastdfs-5.11/make.sh; \
    /fastdfs/fastdfs-5.11/make.sh install;
   
	
WORKDIR /fastdfs/nginx-1.12.1
RUN set -xe;\
    chmod +x /fastdfs/nginx-1.12.1/configure; \
	/fastdfs/nginx-1.12.1/configure --add-module=/fastdfs/fastdfs-nginx-module/src; \
    make; \
    make install;\
	rm -rf /fastdfs;
RUN set -xe;\
    mkdir -p /data/fastdfs/{tracker,storage/store};\
	mkdir -p /data/fdht/storage;\
	mkdir -p /data/conf/{fastdfs,fdht,nginx};\
	mkdir -p /data/nginx/logs;\
	rm -rf /etc/fdfs/;\
	ln -sf /data/conf/fdfs/ /etc/;\
	rm -rf /usr/local/nginx/conf/;\
	ln -sf /data/conf/nginx/ /usr/local/nginx/conf;\
	chmod 777 /data;\
	chmod 777 /data/nginx/logs/;\
	chmod 777 /usr/local/bin/start.bash;
	

STOPSIGNAL SIGTERM

EXPOSE 80 22122 23000 11411

#ENTRYPOINT ["/fastdfs/start.bash"]
CMD ["/usr/local/bin/start.bash","1","1","1","1"]
